package myapp.baselibrary.http;

import android.content.Context;
import android.support.annotation.NonNull;

import java.util.Map;

/**
 * Created by yang2 on 2017/6/23.
 */

public class HttpUtils implements  IHttpEngine{

    private int mType = GET_TYPE;

    private static final int POST_TYPE = 0x0012;

    private static final int GET_TYPE = 0x0011;

    private Context mContext;

    public HttpUtils(Context context){
        this.mContext = context;
    }


    public static HttpUtils with(@NonNull Context context){

        return new HttpUtils(context);

    }

    public HttpUtils post(){
       this. mType = POST_TYPE;
        return this;
    }
    public HttpUtils get(){
        this. mType = GET_TYPE;
        return this;
    }


    private static IHttpEngine mHttpEngine = new OKHttpEngine();



    public static void init(IHttpEngine httpEngine){
        mHttpEngine = httpEngine;
    }
    public void exchancgeEngine(IHttpEngine httpEngine){
        mHttpEngine = httpEngine;
    }

    @Override
    public void get(String url, Map<String, Object> params, EngineCallBack callBack) {
        mHttpEngine.get(url,params,callBack);
    }

    @Override
    public void post(String url, Map<String, Object> params, EngineCallBack callBack) {
        mHttpEngine.post(url,params,callBack);
    }
}
